'''
-*- coding: utf-8 -*-
@File  : v8_det_only.py
@Author: Shanmh
@Time  : 2024/03/19 下午3:17
@Function：
'''
import cv2
from ultralytics import YOLO
import time

img=cv2.imread("asset/images/person.png")
model=YOLO("models/yolov8s.pt")
size=1
fps=0
last_time=0
while True:
    results = model.predict([img]*size, device="cpu")
    for ind_,item in enumerate(results):
        image = item.orig_img
        boxes = item.boxes.cpu().numpy()  # get boxes on cpu in numpy
        for ind, box in enumerate(boxes):  # iterate boxes
            r = box.xyxy[0].astype(int)
            cls = boxes.cls[ind]  #
            cv2.putText(image, f"{cls}", r[:2], color=(155, 15, 0), fontFace=1, fontScale=5, thickness=3)
            cv2.rectangle(image, r[:2], r[2:], (0, 0, 255), 2)
    fps += size
    if time.time() - last_time > 1:
        print(f"[fps]%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ： {fps}")
        last_time = time.time()
        fps = 0

